package logic

import (
	"context"
	"math/rand"
	"mycrm/model/redisinit"
	"time"

	"mycrm/mycrmrpc/internal/svc"
	"mycrm/mycrmrpc/mycrmrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsLogic) SendSms(in *mycrmrpc.SendSmsRequest) (*mycrmrpc.SendSmsResponse, error) {
	// todo: add your logic here and delete this line
	code := rand.Intn(9000) + 1000

	//sms, err := pkg.SendSms(in.Mobile, strconv.Itoa(code))
	//if err != nil {
	//	return nil, err
	//}
	//
	//if *sms.Body.Code == "OK" {
	//	return nil, fmt.Errorf("短信发送失败")
	//}

	redisinit.Client.Set("SendSms"+in.Mobile+in.Source, code, time.Minute*2)
	return &mycrmrpc.SendSmsResponse{}, nil
}
